package cn.xyy.system.api;

import cn.xyy.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.xyy.common.domain.system.auth.UserInfoVO;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.xyy.common.annotation.log.Log;
import cn.xyy.common.domain.mvc.R;

/**
 * 用户接口
 * 
 * @author xyy
 *
 */
@RestController
@RequestMapping(value = "/rest/user")
public class UserRest {

	@Autowired
	private UserService userService;

	@SaCheckPermission("user:list")
	@RequestMapping(value = "getUserListPage", method = RequestMethod.GET)
	public R getUserListPage(UserInfoVO user) {
		return R.ok(userService.getUserListPage(user));
	}

	@RequestMapping(value = "getUser", method = RequestMethod.GET)
	public R getUser(@RequestParam("uid") String uid) {
		return R.ok(userService.getUser(uid));
	}

	@Log("添加用户")
	@SaCheckPermission("user:add")
	@RequestMapping(value = "add", method = RequestMethod.POST)
	public R add(@RequestBody UserInfoVO user) {
		userService.add(user);
		return R.ok();
	}

	@Log("修改用户")
	@SaCheckPermission("user:edit")
	@RequestMapping(value = "update", method = RequestMethod.POST)
	public R update(@RequestBody UserInfoVO user) {
		userService.update(user);
		return R.ok();
	}

	@Log("删除用户")
	@SaCheckPermission("user:del")
	@RequestMapping(value = "delete")
	public R delete(@RequestParam("uid") String uid) {
		userService.delete(uid);
		return R.ok();
	}

	@Log("更新用户状态")
	@SaCheckPermission("user:edit")
	@RequestMapping(value = "updateState", method = RequestMethod.POST)
	public R updateState(@RequestBody UserInfoVO vo) {
		userService.updateState(vo);
		return R.ok();

	}

}
